package chloroform

import java.io.File
import scaladuct._
import junit.framework.Assert._

/**
 * <p>
 * Created by IntelliJ IDEA.
 * User: zslajchrt
 * Date: Feb 20, 2011
 * Time: 10:51:13 PM
 */

class TestFileStarter extends Starter[File] {
  def newInstance() = phaseGetFileName(null)

  def phaseGetFileName(fileName: String) = {
    phaseRewrite(fileName, false)
  }

  def phaseRewrite(fileName: String, @First rewrite: Boolean) = {
    new File(fileName)
  }

  def destroy(instance: File) = null
}

@serializable
@SerialVersionUID(1)
class TestExtensionStarterCookie {
  var name: String = null
}

class TestExtensionStarter(name: String, decorated: ConfigPage[File])
  extends NamedConfigPage[File](name, classOf[TestExtensionStarter]) {

  val getCookie = new TestExtensionStarterCookie

  type Cookie = TestExtensionStarterCookie

  override def consume(cookie: Cookie) = {
    val n = cookie.name
    // process the cookie
    assertEquals("testFile.txt", n);
    NextPage(new TestExtensionStarter2(decorated))
  }
}

class TestExtensionStarter2(decorated: ConfigPage[File]) extends ConfigPageDecorator[File](decorated) {
  override def consume(cookie: Cookie) = {
    super.consume(cookie)
  }
}